package com.cbtx.tablet.device

import android.content.Context
import android.text.TextUtils

/**
 * author : joker.peng
 * e-mail : joker@fiture.com
 * date   : 2021/7/1 11:24 AM
 * desc   :
 */
object MachineFactory {
    private val RK3288_PREFIX = "ZLP86Ni"
    private val RK3399_PREFIX = "ZLP94Ni"
    private val HSV551_PREFIX = "ZLH74Gi"
    private val XL983 = "XL983"
    private val TXCB88 = "TXCB-88"

    /**
     * userdebug 5.1.1 LMY49F eng.server10.20190815.170525 test
     */
    private val ZYSJ_RK3288_CONTAIN = "server10"

    private var sMachine: IMachine? = null

    fun getAutoCreate(context: Context): IMachine {
        if (sMachine == null) {
            synchronized(MachineFactory::class.java) {
                if (sMachine == null) {
                    sMachine = BaseMachine(context)
                }
            }
        }
        return sMachine!!
    }

    /**
     * 判断机型前缀
     *
     * @param model
     * @return
     */
    private fun getPreFix(model: String): String? {
        if (TextUtils.isEmpty(model)) {
            return model
        }
        if (model.startsWith(RK3288_PREFIX)) {
            return RK3288_PREFIX
        } else if (model.startsWith(RK3399_PREFIX)) {
            return RK3399_PREFIX
        } else if (model.startsWith(HSV551_PREFIX)) {
            return HSV551_PREFIX
        } else if (model.contains(ZYSJ_RK3288_CONTAIN)) {
            return ZYSJ_RK3288_CONTAIN
        } else if (model.startsWith(XL983) || model.startsWith(TXCB88)) {
            return XL983
        }
        return model
    }
}